<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
		<title>绑定销售</title>
		<link rel="stylesheet" href="/dvmini/res/plugins/layui/css/layui.css">
		<link rel="stylesheet" href="/dvmini/res/css/style.css" />
		<link rel="stylesheet" href="http://at.alicdn.com/t/font_450595_9jeyu0zh091cerk9.css" />
		<style>
		.layui-layer-btn{
		    padding: 0 10px 30px !important;
		}
		</style>
		
	</head>
	<body style="background-color:#fff;">
	<div class="bindingsection">
		<div class="wrap">
			<div class="bindingbox">
					<div class="bindingbos">
						<span>手&nbsp;&nbsp;&nbsp;机：</span><input type="tel" name="phone" /> 
					</div>
					<div style="position:relative;"  class="bindingbos">
						<span>验证码：</span><input type="tel" name="verifycode" /> <button  id="getcode">获取验证码</button>
					</div>
				
				<a class="sumbitbtn">绑定</a>
			</div>
		</div>
		<input type="text" value="${wxCode}" name="wxCode" style="display:none;">
		<input type="text" value="${wxMiniCode}" name="wxMiniCode" style="display:none;">
		<input type="text" value="${linkurl}" name="linkurl" style="display:none;">
	</div>	
	<div class="bindinged" style="display:none;">
		<h4><i class="iconfont icon-iconfontzhizuobiaozhun023132"></i>温馨提示</h4>
		您的身份已认证，将为您跳转到客服页面...
	</div>
	</body>
	<script src='/dvmini/res/js/jquery.min.js'></script>
	<script src="/dvmini/res/plugins/layui/layui.js" charset="utf-8"></script>
	<script>
	
	var linkurl=$("input[name=linkurl]").val();
	var wxCode=$("input[name=wxCode]").val();
	var wxMiniCode=$("input[name=wxMiniCode]").val();
	layui.use(['form', 'element','layer', ], function() {     
		var form = layui.form(),
			element = layui.element(),
			layer = layui.layer;
			 if(linkurl!==null&&linkurl!==""){
				$(".bindingsection").hide();
				$(".bindinged").show();
				//top.layer.msg("您的身份已认证，将为您跳转到客服页面...");
				setTimeout(function(){
					window.location.href=linkurl;
				},1000)
			}else{
				$(".bindingsection").show();
				$(".bindinged").hide();
			} 
		
			//获取手机验证码
			$("#getcode").on("click",function(){
				var phone=$("input[name=phone]").val();
				if(phone==""){
					top.layer.msg("请填写手机号");
					return false;
				}else{
					if(!(/^1[34578]\d{9}$/.test(phone))) {
						top.layer.msg("手机号码有误，请重填");
						return false;
					}
					$.post("http://www.w1hd.com/api/useragent/agentcode",{phone:phone},function(data){
						console.log(data);
						if(data.code == 0) {
							top.layer.msg('获取验证码成功');
							$("#getcode").addClass('layui-btn-disabled').attr('disabled', true).css({
								"border":"1px solid #ccc",
								"background-color": "#eee",
								"color": "#ccc",
								"pointer-events": "none"
							});
							var i = 60;
							var time = setInterval(function() {
								i--;
								$("#getcode").text(i + ' S')
								if(i == 0) {
									clearInterval(time);
									$("#getcode").removeClass('layui-btn-disabled').attr('disabled', false).css({
										"border":"1px solid #0069FE",
										"background-color": "#fff",
										"color": "#0069FE",
										"pointer-events": "auto"
									});
									$("#getcode").text('获取验证码')
								}
							}, 1000)
						}else{
							top.layer.msg(data.msg);
						}
					})
				}
				
				
			})
		
		//提交
		$(".sumbitbtn").on("click",function(){
			var phone=$("input[name=phone]").val();
			var verifycode=$("input[name=verifycode]").val();
			if(phone==""){
				top.layer.msg("请填写手机号");
				return false;
			}else{
				if(!(/^1[34578]\d{9}$/.test(phone))) {
					top.layer.msg("手机号码有误，请重填");
					return false;
				}
			}
			if(verifycode==""){
				top.layer.msg("请填写验证码");
				return false;
			}
		$.post("http://www.w1hd.com/api/useragent/verifycode",{
				phone:phone,
				verifycode:verifycode
			},function(data){
				console.log(data);
				if(data.code==0){
					//top.layer.msg("绑定成功！")
					 $.get("/dvmini/wx/doRegist",{
							phone:phone,
							wxCode:wxCode,
							wxMiniCode:wxMiniCode
						},function(data){
							console.log(data);
							if(data.code==0){
								var saleid=data.data.id;
								layer.open({
									type:1,
									title:false,
									offset:'30%',
									content:'<div style="text-align:center;padding:3rem 5rem 2rem;font-size:1.04rem; ">恭喜您，绑定成功</div>',
									btnAlign:'c',
									btn:["确定"],
									yes:function(index,layero){
										layer.close(index);
										/* $("input[name=phone]").val("");
										$("input[name=verifycode]").val(""); */

										window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx093940730981162c&redirect_uri="+encodeURI("http://mini.weiyisz.com/wx/chatListView?salesId="+saleid+"")+"&response_type=code&scope=snsapi_base&state=&component_appid=wxce99a8296784e3cc#wechat_redirect";

									}
								})
							}else{
								layer.open({
									type:1,
									title:false,
									offset:'30%',
									content:'<div style="text-align:center;padding:3rem 5rem 2rem;font-size:1.04rem; ">很遗憾，绑定失败</div>',
									btnAlign:'c',
									btn:["确定"],
									yes:function(index,layero){
										layer.close(index);
									}
								})
							}
						})  
					
				}else{
					top.layer.msg(data.msg);
				}
			})
		})
		
		  });
	</script>
</html>